package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.User;
import com.whxy02.tolearn.app.dao.UserDao;
import com.whxy02.tolearn.app.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    private QueryWrapper<User> wrapper=new QueryWrapper<>();
    @Resource
    UserDao userDao;

    @Override
    public List<User> getAll() throws Exception {
        return userDao.selectList(null);
    }

    @Override
    public User getById(Integer id) throws Exception {
        return userDao.selectById(id);
    }

    @Override
    public int save(User user) throws Exception {
       return userDao.insert(user);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return userDao.deleteById(id);
    }

    @Override
    public int change(User user) throws Exception {
        return userDao.updateById(user);
    }

    @Override
    public User getByName(String username) throws Exception {
        wrapper.clear();
        wrapper.eq("username",username);
        return userDao.selectOne(wrapper);
    }
}
